package com.newhope.eshop.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.newhope.eshop.dao.UserMapper;
import com.newhope.eshop.service.api.UserService;
import com.newhope.eshop.service.api.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Slf4j
@Service(interfaceClass = UserService.class, timeout = 10000, version = "2.0.0")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findUser(User user) {
        return userMapper.selectByPrimaryKey(user.getId());
    }

    @Override
    public User findUser(Long userId) {
        User user = new User();
        user.setId(userId);
        return userMapper.findUserByCall(user);
    }

    @Override
    public List<User> findAllUser() {
        return userMapper.findAllList();
    }

    public PageInfo<User> findByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize, true);
        List<User> userList = userMapper.findAllList();
        PageInfo<User> pageInfo = PageInfo.of(userList);
        return pageInfo;
    }

    @Override
    public void addUser(User user) {
        userMapper.addUser(user);
    }
}
